package ar.edu.caece.compiler.grammar.factories;

import ar.edu.caece.compiler.grammar.AbstractTokenVisitorFactory;
import ar.edu.caece.compiler.grammar.TokenVisitor;

public class RELFactory extends AbstractTokenVisitorFactory {

	private static RELFactory INSTANCE;
	
	private REL1Factory rel1Factory;
	private REL2Factory rel2Factory;
	private REL3Factory rel3Factory;
	
	public static RELFactory getInstance() throws Exception {
		if(INSTANCE==null) INSTANCE = new RELFactory();
		return INSTANCE;
	}
	
	private Initializer initializer = new Initializer() {
		
		@Override
		public void init() throws Exception {
			initializer = NoOperationInitializer.getInstance();
			rel1Factory = REL1Factory.getInstance();
			rel2Factory = REL2Factory.getInstance();
			rel3Factory = REL3Factory.getInstance();
		}
	};
	
	private RELFactory() throws Exception {

	}
	
	@Override
	public TokenVisitor makeChainedVisitor(
			final TokenVisitor siguiente) throws Exception {
		initializer.init();

		return rel1Factory.makeChainedVisitor(rel2Factory.makeChainedVisitor(rel3Factory.makeChainedVisitor(siguiente)));
	
	}
	@Override
	public TokenVisitor makeVisitor() throws Exception {
		initializer.init();

		return rel1Factory.makeChainedVisitor(rel2Factory.makeChainedVisitor(rel3Factory.makeVisitor()));
	}
	
	
}
